/**
 *
 */
import Util;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;


init(config: OpenApi.Config){
  super(config);
  @endpointRule = '';
  
  checkConfig(config);
  @endpoint = getEndpoint('opt', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }
  
  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model GetOpenStatusResponseBody = {
  code?: int32(name='Code', example='0'),
  data?: map[string]any(name='Data', example='{"gmtModified":"2021-07-27T04:00:00.000+00:00","mpStatus":1,"id":11,"pk":"1084126944995576","gmtCreate":"2021-07-27T04:00:00.000+00:00","parentPk":"1084126944995576"}'),
  message?: string(name='Message', example='success'),
  requestId?: string(name='RequestId', example='0EB-FCAC-1B78-BBB8-500ED951E9EB'),
  success?: boolean(name='Success', example='true'),
}

model GetOpenStatusResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: GetOpenStatusResponseBody(name='body'),
}

/**
 * @param request GetOpenStatusRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return GetOpenStatusResponse
 */
async function getOpenStatusWithOptions(runtime: Util.RuntimeOptions): GetOpenStatusResponse {
  var req = new OpenApi.OpenApiRequest{};
  var params = new OpenApi.Params{
    action = 'GetOpenStatus',
    version = '2021-07-30',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  if (Util.isUnset(@signatureVersion) || !Util.equalString(@signatureVersion, 'v4')) {
    return callApi(params, req, runtime);
  } else {
    return execute(params, req, runtime);
  }
}

/**
 * @return GetOpenStatusResponse
 */
async function getOpenStatus(): GetOpenStatusResponse {
  var runtime = new Util.RuntimeOptions{};
  return getOpenStatusWithOptions(runtime);
}

model GetOrderInfoRequest {
  listReleased?: boolean(name='ListReleased'),
  relService?: string(name='RelService', description='This parameter is required.', example='MP'),
  resourceType?: int32(name='ResourceType', description='This parameter is required.', example='1'),
}

model GetOrderInfoResponseBody = {
  code?: string(name='Code', example='0'),
  data?: [ 
    {
      bizType?: string(name='bizType'),
      currentConcurrency?: int32(name='currentConcurrency'),
      currentDays?: int32(name='currentDays'),
      instanceId?: string(name='instanceId'),
      isReleased?: boolean(name='isReleased'),
      licenseKey?: string(name='licenseKey'),
      remark?: string(name='remark'),
      totalDays?: int32(name='totalDays'),
    }
  ](name='Data', example='{"licenseKey":"eems7ri3b1u5nui*****","currentConcurrency":2,"instanceId":"opt_mplicense_public_cn-****","totalDays":124,"currentDays":103}'),
  message?: string(name='Message', example='success'),
  requestId?: string(name='RequestId', example='5D6653C5-CA2B-14EC-9CF0-50AA0FF49C31'),
  success?: boolean(name='Success', example='true'),
}

model GetOrderInfoResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: GetOrderInfoResponseBody(name='body'),
}

/**
 * @summary 获取在线license列表
 *
 * @param request GetOrderInfoRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return GetOrderInfoResponse
 */
async function getOrderInfoWithOptions(request: GetOrderInfoRequest, runtime: Util.RuntimeOptions): GetOrderInfoResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.listReleased)) {
    query['ListReleased'] = request.listReleased;
  }
  if (!Util.isUnset(request.relService)) {
    query['RelService'] = request.relService;
  }
  if (!Util.isUnset(request.resourceType)) {
    query['ResourceType'] = request.resourceType;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'GetOrderInfo',
    version = '2021-07-30',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  if (Util.isUnset(@signatureVersion) || !Util.equalString(@signatureVersion, 'v4')) {
    return callApi(params, req, runtime);
  } else {
    return execute(params, req, runtime);
  }
}

/**
 * @summary 获取在线license列表
 *
 * @param request GetOrderInfoRequest
 * @return GetOrderInfoResponse
 */
async function getOrderInfo(request: GetOrderInfoRequest): GetOrderInfoResponse {
  var runtime = new Util.RuntimeOptions{};
  return getOrderInfoWithOptions(request, runtime);
}

model GetOrderUsageRequest {
  licenseKey?: string(name='LicenseKey', description='This parameter is required.'),
  relService?: string(name='RelService', description='This parameter is required.', example='MP'),
  resourceType?: int32(name='ResourceType', description='This parameter is required.', example='1'),
  timeRange?: int32(name='TimeRange', example='1'),
}

model GetOrderUsageResponseBody = {
  data?: [  map[string]any ](name='Data'),
  message?: string(name='Message', example='success'),
  requestId?: string(name='RequestId', example='5D6653C5-CA2B-14EC-9CF0-50AA0FF49C31'),
  success?: boolean(name='Success', example='true'),
}

model GetOrderUsageResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: GetOrderUsageResponseBody(name='body'),
}

/**
 * @param request GetOrderUsageRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return GetOrderUsageResponse
 */
async function getOrderUsageWithOptions(request: GetOrderUsageRequest, runtime: Util.RuntimeOptions): GetOrderUsageResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.licenseKey)) {
    query['LicenseKey'] = request.licenseKey;
  }
  if (!Util.isUnset(request.relService)) {
    query['RelService'] = request.relService;
  }
  if (!Util.isUnset(request.resourceType)) {
    query['ResourceType'] = request.resourceType;
  }
  if (!Util.isUnset(request.timeRange)) {
    query['TimeRange'] = request.timeRange;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'GetOrderUsage',
    version = '2021-07-30',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  if (Util.isUnset(@signatureVersion) || !Util.equalString(@signatureVersion, 'v4')) {
    return callApi(params, req, runtime);
  } else {
    return execute(params, req, runtime);
  }
}

/**
 * @param request GetOrderUsageRequest
 * @return GetOrderUsageResponse
 */
async function getOrderUsage(request: GetOrderUsageRequest): GetOrderUsageResponse {
  var runtime = new Util.RuntimeOptions{};
  return getOrderUsageWithOptions(request, runtime);
}

